<template>
	<view>
		<!-- 懒加载动画 -->
		<view class="loading-box">
			<u-loading :show="loadingone" color="#41ADBA" size="70"></u-loading>
		</view>
		<view v-show="!loadingone">
			<navbar name="菜谱"></navbar>
			<view class="w706 view-food weui-flex">
				<view class="food-image">
					<u-lazy-load border-radius="10" height="129" img-mode="aspectFill" :image="result.pic"></u-lazy-load>
				</view>
				<view class="foodtitle-wiew">
					<view>
						<!-- 香菇蒸鸡腿 -->
						{{result.name}}
					</view>
					<view class="kindView">
						<block v-for="(item,idx) in result.menuinfo" :key="idx">
							<view class="kindItem">
								{{item}}
							</view>
						</block>
					</view>
				</view>
			</view>
			<view class="w706">
				<!-- 标题 -->
				<view class="materials-title">
				</view>
				<view class="materials-title2">
					所需食材
				</view>
				<!-- end -->
				<block v-for="(item,idx) in result.material" :key="idx">
					<view class="weui-flex materia">
						<view class="flex-title">
							{{item}}
							<!-- {{item.title}} -->
						</view>
					<!-- 	<view class="flex-num">
							{{item.num}}
						</view> -->
					</view>
					<u-line v-show="materialsLst.length -1!=idx" />
				</block>
			</view>
			<view class="w706">
				<!-- 标题 -->
				<view class="materials-title">
				</view>
				<view class="materials-title2">
					做法详解
				</view>
				<block v-for="(item,idx) in result.step" :key="idx">
					<view class="weui-flex flex-bz">
						<view class="flex-numtitle">
							<view class="numtitle">
								{{idx+1}}
							</view>
						</view>
						<view class="flex-image">
							<u-lazy-load border-radius="10" height="129" img-mode="aspectFill" :image="item.pic"></u-lazy-load>
						</view>
						<view class="flex-content">
							<!-- {{item.content}} -->
							{{item.detail}}
						</view>
					</view>
					<u-line v-show="result.step.length -1!=idx" />
				</block>
			</view>
			<view style="height: 30upx;">
			</view>
		</view>
	</view>
</template>
<script>
import uLoading from "@/uview-ui/components/u-loading/u-loading.vue"

import uLine from "@/uview-ui/components/u-line/u-line.vue"
import uLazyLoad from "@/uview-ui/components/u-lazy-load/u-lazy-load.vue"

	export default {
		components: {
			uLoading,
			uLazyLoad,
			uLine,

		},
		data() {
			return {
				result:'',
				loadingone: false,
				practiceList: [
				],
				materialsLst: [],
				kindList: [],
				pageCurrent:1,//页数
				pageSize:1,//条数
			}
		},
		onLoad(e) {
			this.getByIdCp(e.id)
		},
		methods: {
			getByIdCp(id) {
				let _this = this;
				let fdata = {
					id:id
				}
				this.$api.get(global.apiUrls.getByIdCp, fdata)
					.then(res => {
						if (res.data.code == 1000) {
							console.log(res.data)
							let result = res.data.result;
							// 功效
							result.menuinfo = result.menuinfo.replace("[", "")
							result.menuinfo = result.menuinfo.replace("]", "")
							result.menuinfo = result.menuinfo.split(',')
							// 食材
							result.material = result.material.replace("[", "")
							result.material = result.material.replace("]", "")
							result.material = result.material.split(',')
							// 做法
							result.step = JSON.parse(result.step)
							for(let i = 0;i<result.step.length;i++){
								result.step[i].detail = result.step[i].detail.replace("[ ,", "")
								result.step[i].detail = result.step[i].detail.replace(", ]", "")
							}
							console.log(result.step,152222)
							_this.result = result;//菜谱详情
							
							// for (let i = 0; i < records.length; i++) {
							// 	records[i].menuinfo = records[i].menuinfo.replace("[", "")
							// 	records[i].menuinfo = records[i].menuinfo.replace("]", "")
							// 	records[i].menuinfo = records[i].menuinfo.split(',')
							// }
							// if (onReach) { //分页
							// 	_this.records = _this.records.concat(records)
							// } else {
							// 	_this.records = records
							// }
			
						}
					})
			},
		}
	}
</script>
<style lang="scss">
	.w706 {
		width: 706upx;
		margin: 30upx auto 0;
		background: #fff;
		border-radius: 25upx;
	}

	.view-food {
		padding: 22upx 25upx 20upx;

		.food-image {
			width: 129upx;
			height: 129upx;
		}

		.foodtitle-wiew {
			padding: 12upx 0 0 20upx;
			font-size: 26upx;
			font-weight: 500;
			color: #4A4A4A;
			line-height: 37upx;
		}

		.kindView {
			width: 526upx;
			margin-left: -20upx;

			.kindItem {
				display: inline-block;
				padding: 4upx 10upx;
				margin: 25upx 0 0 20upx;
				background: #2EA7E0;
				border-radius: 8upx;
				font-size: 24upx;
				font-weight: 400;
				color: #FFFFFF;
				line-height: 33upx;
			}
		}
	}

	.materials-title {
		height: 90upx;
		line-height: 90upx;
		padding: 0 20upx;
		background: linear-gradient(112deg, #81C042 0%, #2EA7E0 100%);
		opacity: 0.23;
		border-radius: 25upx 25upx 0 0;
	}

	.materials-title2 {
		height: 40upx;
		line-height: 40upx;
		transform: translateY(-60upx);
		color: #2EA7E0;
		padding-left: 20upx;
		margin-bottom: -40upx;
	}

	.materia {
		height: 90upx;
		padding: 0 20upx;
		line-height: 90upx;

		.flex-title {
			width: 50%;
			font-size: 34upx;
			font-weight: 400;
			color: #333333;
		}

		.flex-num {
			width: 49%;
			font-size: 30upx;
			font-weight: 500;
			color: #333333;
			text-align: right;
		}
	}

	.flex-bz {
		padding: 30upx;
	}

	.flex-numtitle {
		width: 70upx;

		.numtitle {
			width: 40upx;
			height: 40upx;
			background: #2EA7E0;
			line-height: 40upx;
			text-align: center;
			border-radius: 50%;
			color: #fff;
			position: relative;
			top: 50upx;
			margin-right: 10upx;
		}

		.numtitle:before {
			content: '';
			width: 46upx;
			height: 46upx;
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50%, -50%);
			border-radius: 50%;
			border: 1px solid #2EA7E0;
		}
	}

	.flex-image {
		width: 195upx;
		height: 138upx;
		background: #D8D8D8;
		border-radius: 8upx;
		border: 1upx solid #979797;
	}

	.flex-content {
		width: 380upx;
		padding-left: 20upx;
		font-size: 26upx;
		font-weight: 400;
		color: #4A4A4A;
		line-height: 37upx;
	}
</style>
